/****************************************************/
/* Project Name:部门信息管理                             */
/* File Name:TdcDepartmentController             */
/* Date:2017年3月22日下午19:14:12            */
/* Description:部门信息的业务逻辑层控制器        */
/****************************************************/ 
package com.thinkgem.jeesite.modules.tdc.department.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.tdc.department.entity.TdcDepartment;
import com.thinkgem.jeesite.modules.tdc.department.service.TdcDepartmentService;

/**
 * 部门信息Controller
 * @author 孙瑞曦
 * @version 2017-03-20
 */
@Controller
@RequestMapping(value = "${adminPath}/department/tdcDepartment")
public class TdcDepartmentController extends BaseController {

	@Autowired
	private TdcDepartmentService tdcDepartmentService;
	
	@ModelAttribute
	public TdcDepartment get(@RequestParam(required=false) String id) {
		TdcDepartment entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tdcDepartmentService.get(id);
		}
		if (entity == null){
			entity = new TdcDepartment();
		}
		return entity;
	}
	/**
	 * list:(分类管理页面，获取所有的部门信息)
	 * @param tdcDepartment 部门表的实体类对象
	 * @param request		向服务器提交pagesize和pageNo的信息
	 * @param response	  	向客户端回应返回来的pagesize和pageno信息
	 * @param model			部门表的实体类entity
	 * @return				返回到分类查询页面
	 */
	@RequiresPermissions("department:tdcDepartment:view")
	@RequestMapping(value = {"list", ""})
	public String list(TdcDepartment tdcDepartment, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TdcDepartment> page = tdcDepartmentService.findPage(new Page<TdcDepartment>(request, response), tdcDepartment); 
		model.addAttribute("page", page);
		return "tdc/department/tdcDepartmentList";
	}
	/**
	 * form:(部门信息录入)
	 * @param tdcDepartment	部门表的实体类对象
	 * @param model			部门表的实体类对象
	 * @return				进入到基础信息录入页
	 */
	@RequiresPermissions("department:tdcDepartment:view")
	@RequestMapping(value = "form")
	public String form(TdcDepartment tdcDepartment, Model model) {
		model.addAttribute("tdcDepartment", tdcDepartment);
		return "tdc/department/tdcDepartmentForm";
	}
	/**
	 * save:(保存录入的部门信息)
	 * @param tdcDepartment 部门表的实体类对象
	 * @param model		部门表的实体类entity
	 * @param redirectAttributes 保存成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("department:tdcDepartment:edit")
	@RequestMapping(value = "save")
	public String save(TdcDepartment tdcDepartment, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tdcDepartment)){
			return form(tdcDepartment, model);
		}
		tdcDepartmentService.save(tdcDepartment);
		addMessage(redirectAttributes, "保存部门信息成功");
		return "redirect:"+Global.getAdminPath()+"/department/tdcDepartment/?repage";
	}
	/**
	 * delete:(在部门分类查询中，根据id删除部门的信息)
	 * @param tdcDepartment 部门表的实体类对象
	 * @param redirectAttributes 保存成功后的提示信息
	 * @return 返回到list方法
	 */
	@RequiresPermissions("department:tdcDepartment:edit")
	@RequestMapping(value = "delete")
	public String delete(TdcDepartment tdcDepartment, RedirectAttributes redirectAttributes) {
		tdcDepartmentService.delete(tdcDepartment);
		addMessage(redirectAttributes, "删除部门信息成功");
		return "redirect:"+Global.getAdminPath()+"/department/tdcDepartment/?repage";
	}

}